Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check language version for more ref-struct-interfaces scenarios #73586

Merged
merged 1 commit into from
May 20, 2024

Conversation

AlekseyTs
Copy link
Contributor

@AlekseyTs AlekseyTs commented May 20, 2024

The following unit-test reflects behavior of the compiler without the feature merged:

        [Fact]
        public void Test()
        {
            // public ref struct S : IEnumerable<int>
            // {
            //     IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw null;
            //     System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null;
            // }

            var il = @"
.class public sequential ansi sealed beforefieldinit S
    extends [mscorlib]System.ValueType
    implements class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>,
               [mscorlib]System.Collections.IEnumerable
{
    .custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (
        01 00 00 00
    )
    .custom instance void [mscorlib]System.ObsoleteAttribute::.ctor(string, bool) = (
        01 00 52 54 79 70 65 73 20 77 69 74 68 20 65 6d
        62 65 64 64 65 64 20 72 65 66 65 72 65 6e 63 65
        73 20 61 72 65 20 6e 6f 74 20 73 75 70 70 6f 72
        74 65 64 20 69 6e 20 74 68 69 73 20 76 65 72 73
        69 6f 6e 20 6f 66 20 79 6f 75 72 20 63 6f 6d 70
        69 6c 65 72 2e 01 00 00
    )
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::.ctor(string) = (
        01 00 0a 52 65 66 53 74 72 75 63 74 73 00 00
    )

    .pack 0
    .size 1

    // Methods
    .method private final hidebysig newslot virtual 
        instance class [mscorlib]System.Collections.Generic.IEnumerator`1<int32> 'System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator' () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
            01 00 01 00 00
        )
        .override method instance class [mscorlib]System.Collections.Generic.IEnumerator`1<!0> class [mscorlib]System.Collections.Generic.IEnumerable`1<int32>::GetEnumerator()
        // Method begins at RVA 0x2050
        // Code size 2 (0x2)
        .maxstack 8

        IL_0000: ldnull
        IL_0001: throw
    } // end of method S::'System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator'

    .method private final hidebysig newslot virtual 
        instance class [mscorlib]System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator () cil managed 
    {
        .custom instance void [mscorlib]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = (
            01 00 01 00 00
        )
        .override method instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Collections.IEnumerable::GetEnumerator()
        // Method begins at RVA 0x2050
        // Code size 2 (0x2)
        .maxstack 8

        IL_0000: ldnull
        IL_0001: throw
    } // end of method S::System.Collections.IEnumerable.GetEnumerator

} // end of class S
";

            var src = """
class C
{
    static void Main()
    {
        foreach (var i in new S())
        {
        }
    }
}
""";
            var comp = CreateCompilationWithIL(src, il);

            comp.VerifyDiagnostics();

            comp.VerifyEmitDiagnostics(
                // error CS7038: Failed to emit module 'ec94a2fe-ba35-45d7-bd85-e440088ca75c': Unable to determine specific cause of the failure.
                Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments("ec94a2fe-ba35-45d7-bd85-e440088ca75c", "Unable to determine specific cause of the failure.").WithLocation(1, 1)
                );
        }

@AlekseyTs AlekseyTs requested review from jjonescz and cston May 20, 2024 15:26
@AlekseyTs AlekseyTs requested a review from a team as a code owner May 20, 2024 15:26
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label May 20, 2024
@AlekseyTs
Copy link
Contributor Author

@cston, @jjonescz, @dotnet/roslyn-compiler For the second review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - RefStructInterfaces untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants